<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
//=======QUICK LINKS============================================================================================================//
if ($_POST["action"]=="quicklinks")
{
	if ($_POST["link"]=="")
	{
		header("Location: ".$_POST["currentpagelinkurl"]);
		exit;
	}

	if ($_POST["link"]=="addcurrentpage")
	{
		$sql="INSERT INTO quicklinks SET
			username='".LOGGEDIN_USERNAME."',
			linkname='".$_POST["addcurrentpagelinkname"]."',
			linkurl='".$_POST["currentpagelinkurl"]."'";
		$insert=db_query($sql);
		
		header("Location: ".$_POST["currentpagelinkurl"]);
		exit;
	}
	
	if ($_POST["link"]=="customize")
	{
		header("Location: /admin/quicklinks.html");
		exit;
	}

	if (is_numeric($_POST["link"]))
	{
		$sql="SELECT linkurl FROM quicklinks WHERE id='".$_POST["link"]."'";
		$row=db_fetch_result(db_query($sql));
	
		$location=urldecode($row["linkurl"]);
		
		if (!preg_match("#^http://#",$location))
		{
			$location="http://".$location;
		}
		
		header("Location: ".$location);
		exit;
	}
}


//=======QUICK LINKS - ADD======================================================================================================//
if ($_POST["action"]=="addquicklinks")
{
	
	$_SESSION["sessdata"]["linkname"]=htmlspecialchars($_POST["linkname"]);
	$_SESSION["sessdata"]["linkurl"]=urlencode($_POST["linkurl"]);
	
	if ($_SESSION["sessdata"]["linkname"]=="" || $_SESSION["sessdata"]["linkurl"]=="")
	{
		$_SESSION["sessdata"]["displaymessage"]="<h2 class=\"highlight\">ERROR -- Please fill in all fields!</h2>";
		
		header("Location: /admin/quicklinks.html");
		exit;
	}
	
	$sql="INSERT INTO quicklinks SET
		username='".LOGGEDIN_USERNAME."',
		linkname='".$_SESSION["sessdata"]["linkname"]."',
		linkurl='".$_SESSION["sessdata"]["linkurl"]."'";
	$insert=db_query($sql);
	
	unset($_SESSION["sessdata"]["linkname"]);
	unset($_SESSION["sessdata"]["linkurl"]);

	header("Location: /admin/quicklinks.html");
	exit;
	
}


//=======QUICK LINKS - EDIT=====================================================================================================//
if ($_POST["action"]=="editquicklinks")
{
	
	$_SESSION["sessdata"]["linkname"]=htmlspecialchars($_POST["linkname"]);
	$_SESSION["sessdata"]["linkurl"]=urlencode($_POST["linkurl"]);
	
	if ($_SESSION["sessdata"]["linkname"]=="" || $_SESSION["sessdata"]["linkurl"]=="")
	{
		$_SESSION["sessdata"]["displaymessage"]="<h2 class=\"highlight\">ERROR -- Please fill in all fields!</h2>";
		
		header("Location: quicklinks.html?page=edit&id=".$_POST["id"]);
		exit;
	}
	
	$sql="UPDATE quicklinks SET username='".LOGGEDIN_USERNAME."',
	linkname='".$_SESSION["sessdata"]["linkname"]."',
	linkurl='".$_SESSION["sessdata"]["linkurl"]."' WHERE
	id='".$_REQUEST["id"]."'";
	$insert=db_query($sql);
	
	unset($_SESSION["sessdata"]["linkname"]);
	unset($_SESSION["sessdata"]["linkurl"]);

	header("Location: quicklinks.html");
	exit;
	
}


//=======QUICK LINKS - DELETE===================================================================================================//
if ($_REQUEST["action"]=="deletequicklinks")
{
	if ($_REQUEST["id"]=="")
	{
		header("Location: quicklinks.html");
		exit;
	}
	
	$sql="DELETE FROM quicklinks WHERE id='".$_REQUEST["id"]."'";
	$delete=db_query($sql);

	header("Location: quicklinks.html");
	exit;
	
}


header("Location: /index.html");
exit;

?>
